<?php
session_start();
include_once('inc/connection.php');

$exist = false;
$user = $_POST['userName'];
$pass = $_POST['password'];
$date = date('y-m-d');
$fName = $_POST['fName'];
$lName = $_POST['lName'];
$email = $_POST['eMail'];
$creditnumber = $_POST['credit'];
$sql = "SELECT * FROM `users`";
            //$result = mysql_query("SELECT * FROM product");
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
    if ($user == $row['uname']) {
        $exist = true;
    }
}
if (!$exist) {
    mysql_query("insert into users (first,last,uname,pass,registeredDate,email)
    
    				VALUES ('$fName','$lName','$user','$pass','$date','$email') ");
  
 


 try{
       $conn = new Mongo('mongodb-env-ecom.whelastic.net', array("username" => 'admin', "password" => 'Yar66WQObe'));
 
 $db = $conn->test;
   if ($conn){
     //echo "<center><h1>Good connection</h1></center>";
     	$db = $conn->mongodbconnection;
     $collection = $db->login;
     //$cursor = $collection->find();

$document = array( "first" => $fName, "last" => $lName,
                  "uname" => $user , "pass" => $pass
                 , "registeredDate" => $date, "email" => $email);
$collection->insert($document);
     

   }
 
 }catch( Exception $e){
 
       echo  "<center><h1>Doesn't work</h1></center>";
 
       exit;
 
 
} 
 


    $sql = "SELECT * FROM `users`";
	
	mysql_query("insert into bank (accountNum,email) VALUES ('$creditnumber','$email') "); 
	
            $result = mysql_query("SELECT * FROM users");
    $result = mysql_query($sql);
   /*.. while ($row = mysql_fetch_array($result)) {
        if ($user == $row['userName'] && $pass == $row['password']) {
//        echo 'da5al  ' . $user . '  ' . $pass . '  ';
            $_SESSION['id'] = $row['id'];
            $_SESSION['name'] = $row['firstName'];
            $_SESSION['lname'] = $row['lasttName'];
            $_SESSION['role'] = $row['role'];
            $_SESSION['lang'] = 'en';
        } else {
//        echo 'la3d  ' . $user . '  ' . $pass . '  ';
        }
    }
    
	*/
    }
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    ?>
    <html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8" />
            <meta name="Hasan" content="EC" />

            <link rel="shortcut icon" href="tsc.ico" />
            <link href="css/en/mycss.css" rel="Stylesheet" type="text/css" />
            <link href="css/en/header.css" rel="Stylesheet" type="text/css" />
            <link href="css/en/login.css" rel="Stylesheet" type="text/css" />

            <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
            <script src="js/header.js"></script>
            <title></title>
        </head>

        <body>

            <!--        <form action="../inc/login.php"  method="post" enctype="multipart/form-data">
                        <div id="loginArea">
                            <ul>
                                <li>
                                    <div id="loginTitle">
            <?php
            if (isset($_SESSION['name']))
                echo '<a href="javascript:void(0)"><p style="font-size: 12px; color: lightblue;"> ' . $_SESSION['name'] . '</p></a>';
            else
                echo '<a href="javascript:void(0)"><p style="font-size: 12px; color: lightblue;">Login/Register</p></a>';
            ?>
                                    </div>
                                </li>
                                <li>
                                    <div id="loginFields">
                                         <p style="float: left;font-size: 12px; color: white;">user name</p> 
            <?php
            if (isset($_SESSION['name']))
                echo '<div id="loggedInDiv">
                            <a href="logout.php" > تسجيل خروج</a>
                            <a href="../companyAddProduct.php" >صفحة الإدارة</a>
                            </div>';
            else
                echo '<input style="margin-right: 5px;float: right;" type="text" name="user" value="user name" class="grayClass" content="user name" />
                    <p style="float: left;font-size: 12px; margin-left: 10px; color: white;">password</p>
                    <input style="margin-right: 5px;float: right;" type="password" name="pass" value="password" content="password" class="grayClass"/>
                    <input id="login" type="submit" value="login"/>
                    <input id="register" type="button" value="Register"/>';
            ?>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </form>
            
                    <div id="header">
                        <ul id="homeButtonUL">
                            <a href="../index.php"><li class="homeButton" ><img src="../images/home.png" width="30px"/></li></a>
                            <li class="headerLogo"><img src="../images/logo.png" width="80px"/></li>
                        </ul>
                        <ul id="cartButton">
                            <a href="../products.php"><li class="cartNav"><img src="../images/cart.png" width="25px"/>
                                    <p>البضائع</p>
                                </li></a>
                        </ul>
                        <ul id="headerNavLinksUL">
                        </ul>
                    </div>-->
            <?php
            include 'inc/header.php';
            ?>
        <div id="welcomeDiv">
            <div id="welcomeDivImg">
                <img src="images/slider.jpg" width="200px"/>
            </div>
            <a href="index.php">الرئيسية</a>
        </div>

    </body>
</html>
